package ac.github.os.internal.core.action.event

import ac.github.os.internal.core.action.Action
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.config.get
import ac.github.os.internal.core.holder.EventHolder
import ac.github.os.internal.session.Cache
import ac.github.os.internal.session.Session
import org.bukkit.event.Cancellable
import taboolib.common.platform.Awake

@Awake
class EventCancel : Action {
    override fun onExecute(session: Session, cache: Cache, config: StringConfig) {
        val holder = session.holder
        if (holder is EventHolder<*> && holder.allowCancel) {
            (holder.event as Cancellable).isCancelled = config.get("val",true,single = true)!!
        }
    }

    override val type: Action.Type
        get() = Action.Type.AIR
    override val namespace: String
        get() = "event:cancel"
}